package com.mifengs.mall.floor;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.annotation.ItemProviderTag;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.mifengs.mall.R;
import com.mifengs.mall.adapter.TwoGridtemAdapter;
import com.mifengs.mall.entity.AdvertBean;
import com.mifengs.mall.entity.FloorBean;
import com.mifengs.mall.util.ToIntentUtil;

import java.util.List;

/**
 * Created by lihaoqi on 2018/4/16.
 */

@ItemProviderTag(
        viewType = FloorListAdapter.TYPE_SIX,
        layout = R.layout.fragment_two_flo
)
public class FloorSixItemProvider extends BaseItemProvider<FloorBean, BaseViewHolder> {


    private TwoGridtemAdapter mTwoGridtemAdapter;

    @Override
    public void convert(BaseViewHolder helper, FloorBean floorBean, int position) {
        RecyclerView recyclerView = helper.getView(R.id.two_grid_list);
        if (floorBean != null) {
            final List<AdvertBean> advertBeanList = floorBean.getAdverts();
            recyclerView.setLayoutManager(new GridLayoutManager(mContext, 2));
            recyclerView.setNestedScrollingEnabled(false);
            mTwoGridtemAdapter = new TwoGridtemAdapter(R.layout.item_two_grid_flo, advertBeanList, mContext);
            recyclerView.setAdapter(mTwoGridtemAdapter);
            mTwoGridtemAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                    AdvertBean adverts = advertBeanList.get(position);
                    ToIntentUtil.toCommonIntent(adverts.getActionUrl(), mContext);
                }
            });
        }
    }

    @Override
    public void onClick(BaseViewHolder helper, FloorBean floorBean, int i) {

    }

    @Override
    public boolean onLongClick(BaseViewHolder helper, FloorBean floorBean, int i) {
        return false;
    }
}
